package pl.com.like.sequoia.web.handlers;

import java.io.IOException;
import java.util.Locale;

import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;

public class CustomViewHandler extends ViewHandler {

	private final ViewHandler parent;

	public CustomViewHandler(ViewHandler parent) {
		this.parent = parent;
	}

	@Override
	public Locale calculateLocale(FacesContext arg0) {
		return parent.calculateLocale(arg0);
	}

	@Override
	public String calculateRenderKitId(FacesContext arg0) {
		return parent.calculateRenderKitId(arg0);
	}

	@Override
	public UIViewRoot createView(FacesContext context, String view) {
		return parent.createView(context, view);
	}

	@Override
	public String getActionURL(FacesContext context, String arg1) {
		return parent.getActionURL(context, arg1);
	}

	public ViewHandler getParent() {
		return parent;
	}

	@Override
	public String getResourceURL(FacesContext context, String arg1) {
		return parent.getResourceURL(context, arg1);
	}

	@Override
	public void renderView(FacesContext context, UIViewRoot arg1) throws IOException, FacesException {
		parent.renderView(context, arg1);
	}

	@Override
	public UIViewRoot restoreView(FacesContext context, String arg1) {
		UIViewRoot root = null;
		root = parent.restoreView(context, arg1);
		if (root == null) {
			root = createView(context, arg1);
		}
		return root;

	}

	@Override
	public void writeState(FacesContext context) throws IOException {
		parent.writeState(context);
	}

}
